package com.hanscan.persistence.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@Table(name = "users")
@Inheritance(strategy = InheritanceType.JOINED)
@SequenceGenerator(name = "userGen", sequenceName = "userGen", allocationSize =
1)
@NamedQueries(
{
//    @NamedQuery(name = "getAllClients",
//    query = "SELECT u FROM Client u WHERE u.resigntDate is null"),
//    @NamedQuery(name = "getValidation",
//    query = "SELECT u FROM Client u WHERE u.birthday = \'?1\'"),
    @NamedQuery(name = "findUsertById",
    query = "SELECT u FROM User u " +
    "WHERE u.userId=?1 and u.resigntDate is null"),
    @NamedQuery(name = "findCompany",
    query = "SELECT u FROM User u WHERE u.company.companyId=?1 and u.resigntDate is null"),
    @NamedQuery(name = "findUserByNsp",
    query = "SELECT u FROM User u " +
    "WHERE UPPER(u.nsp)=?1"),
    @NamedQuery(name = "findUserByName",
    query = "SELECT u FROM User u " +
    "WHERE UPPER(u.name) LIKE ?1 and u.resigntDate is null"),
    @NamedQuery(name = "findUserByClientLogin",
    query = "SELECT u FROM User u " +
    "WHERE u.clientLogin LIKE ?1 and u.resigntDate is null"),
    @NamedQuery(name = "findUserBySurname1",
    query = "SELECT u FROM User u " +
    "WHERE UPPER(u.surname1) LIKE ?1 and u.resigntDate is null"),
    @NamedQuery(name = "findUserByNameAndSurname1",
    query = "SELECT u FROM User u " +
    "WHERE UPPER(u.name) LIKE ?1 and UPPER(u.surname1) LIKE ?2 and u.resigntDate is null"),
    @NamedQuery(name = "findUserByNameAndNSP",
    query = "SELECT u FROM User u " +
    "WHERE UPPER(u.name) LIKE ?1 and u.nsp =?2 and u.resigntDate is null"),
    @NamedQuery(name = "findUserBySurnameAndNSP",
    query = "SELECT u FROM User u " +
    "WHERE UPPER(u.surname1) LIKE ?1 and u.nsp =?2 and u.resigntDate is null"),
    @NamedQuery(name = "findClientByUserNameAndPassword",
    query = "SELECT u FROM User u " +
    "WHERE u.clientLogin=?1 " +
    "and u.clientPassword=?2 " +
    "and u.resigntDate is null")
})
public class User implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userGen")
    private Long userId;

    //Atributos
    @Column(nullable = false)
    private String name;
    @Column(nullable = false)
    private String surname1;
    private String surname2;
    @Column(nullable = false)
    private String nsp;
    @Column(nullable = false)
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date birthday;
    @Column(nullable = false)
    private boolean gender;
    private String telephone;
    private String email;
    private String address;
    private String zipCode;
    private String province;
    private String city;
    private String country;
    private String clientLogin;
    private String clientPassword;
    private byte[] photo;
    @Temporal(TemporalType.TIMESTAMP)
    private Date resigntDate;
    @ManyToOne
    private UserType userType;
    @ManyToOne
    private Company company;
    @OneToMany(cascade = CascadeType.ALL, fetch =
    FetchType.LAZY)
    private List<BioTemplate> bioTemplates;


    public User()
    {
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

    public String getClientLogin() {
        return clientLogin;
    }

    public void setClientLogin(String clientLogin) {
        this.clientLogin = clientLogin;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public boolean isGender()
    {
        return gender;
    }

    public void setMan(boolean gender)
    {
        this.gender = gender;
    }

    public String getClientPassword() {
        return clientPassword;
    }

    public void setClientPassword(String clientPassword) {
        this.clientPassword = clientPassword;
    }

    public byte[] getPhoto()
    {
        return photo;
    }

    public void setPhoto(byte[] photo)
    {
        this.photo = photo;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public List<BioTemplate> getBioTemplates()
    {
        return bioTemplates;
    }

    public void setBioTemplates(List<BioTemplate> bioTemplates)
    {
        this.bioTemplates = bioTemplates;
    }

    public String getCity()
    {
        return city;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public String getCountry()
    {
        return country;
    }

    public void setCountry(String country)
    {
        this.country = country;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    public String getSurname1()
    {
        return surname1;
    }

    public void setSurname1(String surname1)
    {
        this.surname1 = surname1;
    }

    public String getSurname2()
    {
        return surname2;
    }

    public void setSurname2(String surname2)
    {
        this.surname2 = surname2;
    }

    public String getTelephone()
    {
        return telephone;
    }

    public void setTelephone(String telephone)
    {
        this.telephone = telephone;
    }

    public String getProvince()
    {
        return province;
    }

    public void setProvince(String province)
    {
        this.province = province;
    }

    public Date getResigntDate()
    {
        return resigntDate;
    }

    public void setResigntDate(Date resigntDate)
    {
        this.resigntDate = resigntDate;
    }

    public String getZipCode()
    {
        return zipCode;
    }

    public void setZipCode(String zipCode)
    {
        this.zipCode = zipCode;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getNsp() {
        return nsp;
    }

    public void setNsp(String nsp) {
        this.nsp = nsp;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

}
